
var Popup = new Class({
		
		Implements: Options,
		
		options: {
			directories: "",
			menubar: "",
			status: "",
			location: "",
			scrollbars: "",
			resizable: "",
			height: "",
			width: "",
			left: "",
			top: "",
			fullscreen: "",
			autoCenter: false
			
		},
		
    initialize : function (a, options){
			this.setOptions(options);
			
			this.elm = $(a);
			this.optionsStr = this.stringifyOptions(this.options);

			this.elm.addEvent("click", function (e){
				e.stop();
				window.open(this.elm.href, "_blank", this.optionsStr);
			}.bind(this))
		},
		
		stringifyOptions: function (){
			var txt = "";
			
			for(var prop in this.options){
				if(this.options[prop] != "" && $type(this.options[prop]) == "string") txt += prop + "=" + this.options[prop] + ",";
			}
			
			// pour le mode fullscreen, on eneleve les attributs width et height
			if(this.options.fullscreen == "yes") txt = txt.replace(/(width|height)=[0-9]*(px|%),/g, "");
			
			// pour le mode autoCenter, on remplace les attributs left et top
			if(this.options.autoCenter == true) {
				var w = Math.min(document.body.scrollWidth, document.documentElement.clientWidth);
				var h = Math.min(document.body.scrollHeight, document.documentElement.clientHeight);
				var left = Math.round((w - this.options.width.toInt())/2);
				var top = Math.round((h - this.options.height.toInt())/2);
				txt = txt.replace(/(left|top)=[0-9]*(px|%),/g, "");
				txt += "left=" + left + "px,top="+ top + "px,";
			}
			
			// on enleve la derniere ,
			txt = txt.substr(0, txt.length-1);
			return txt;
		}
});
Moodule.register("Popup","a.popup", {left: "20px",top: "20px",width: "500px",height: "200px",autoCenter: true});
Moodule.register("Popup","a.popupFullscreen", {directories: "no",menubar: "no",status: "no",location: "no",fullscreen: "yes"});